const bcrypt = require('bcryptjs');
const { PrismaClient } = require('@prisma/client');

const prisma = new PrismaClient();

async function createTestUser() {
  try {
    // Hash password
    const passwordHash = await bcrypt.hash('123456', 12);
    
    // Create test user
    const user = await prisma.user.create({
      data: {
        username: 'testuser',
        email: 'test@example.com',
        passwordHash: passwordHash
      }
    });
    
    console.log('Test user created successfully:', user);
    
    // Create default todo list for the user
    await prisma.todoList.create({
      data: {
        name: '我的任务',
        userId: user.id
      }
    });
    
    console.log('Default todo list created for user');
    
  } catch (error) {
    console.error('Error creating test user:', error);
  } finally {
    await prisma.$disconnect();
  }
}

createTestUser();